Skip to content

Backport tenant-leading ClickHouse sort key + LowCardinality (2.4.x → 2.4.3)#127

Merged
lohanidamodar merged 1 commit into
2.4.xfrom
feat/2.4.x-tenant-sort-key
Jun 22, 2026
Merged

Backport tenant-leading ClickHouse sort key + LowCardinality (2.4.x → 2.4.3)#127
lohanidamodar merged 1 commit into
2.4.xfrom
feat/2.4.x-tenant-sort-key

Conversation

@lohanidamodar

Copy link
Copy Markdown
Contributor

Why

Appwrite Cloud is locked to utopia-php/database 5.* (via server-ce), so it cannot consume audit 2.5.0/2.6.0, both of which require database ^6.0.0. This backports the tenant-leading ClickHouse sort-key work from #126 (released in 2.6.0) onto the 2.4.x maintenance line, which stays on database 5.*.

What

Same logical change as #126, adapted to the 2.4.2 adapter structure:

  • Tenant-leading sort key in setup()'s CREATE TABLE: ORDER BY (tenant, time, id) when sharedTables is enabled, otherwise ORDER BY (time, id).
  • allow_nullable_key = 1 appended to SETTINGS only for shared tables (tenant is Nullable(UInt64)).
  • LowCardinality columns in the CREATE TABLE column definitions only: event, actorType, resourceTypeLowCardinality(String); countryLowCardinality(Nullable(String)) (nullable wrapped inside).
  • Live test ClickHouseTest::testSharedTableSortKeyLeadsWithTenant() asserts system.tables.sorting_key leads with tenant (runs against the docker-compose ClickHouse in CI).

No projection / getSortingKey / migration logic is introduced — the library stays fresh-schema-only. Index set and query() visibility are unchanged.

Verification

  • composer install resolves utopia-php/database 5.0.0 (database stays on 5.*).
  • phpunit tests/Audit/QueryTest.php → 11 passed.
  • pint --test → pass; phpstan analyse --level max src tests → no errors.
  • php -l clean on changed files. The live ClickHouse test passes in CI; locally it errors only on connection.

Release

Should be released as 2.4.3.

… (2.4.x)

Targets the database-5 2.4.x maintenance line so Appwrite Cloud (locked to
utopia-php/database 5 via server-ce) can consume it. The 2.5.0/2.6.0 releases
require database ^6.0.0 and are unusable by cloud.

Same logical change as #126:
- setup() CREATE TABLE: tenant-leading ORDER BY (tenant, time, id) when
  sharedTables is enabled, otherwise (time, id); allow_nullable_key = 1 only
  emitted for shared tables (tenant is Nullable(UInt64)).
- event/actorType/resourceType -> LowCardinality(String) and country ->
  LowCardinality(Nullable(String)) in CREATE TABLE column definitions only.
- Live test testSharedTableSortKeyLeadsWithTenant asserts sorting_key leads
  with tenant.

No projection/migration/getSortingKey logic; fresh-schema-only.
@greptile-apps

greptile-apps Bot commented Jun 22, 2026

Copy link
Copy Markdown

Greptile Summary

  • Backports the ClickHouse shared-table schema improvements to the 2.4.x maintenance line.
  • Updates fresh ClickHouse table creation so shared tables use a tenant-leading sort key and enable nullable-key support for nullable tenant values.
  • Changes selected string dimension columns to LowCardinality types in the generated schema.
  • Adds a live ClickHouse test that verifies shared-table sorting starts with tenant.

Confidence Score: 5/5

The changes are focused on fresh ClickHouse schema creation and include targeted coverage for the shared-table sorting key behavior.

The touched adapter logic matches the described backport scope, existing query behavior is unchanged, and the added live test covers the key schema invariant.

T-Rex T-Rex Logs

What T-Rex did

  • Ran a baseline ClickHouse schema check on the base branch to establish the initial contract state; observed php_available is False and most contract markers report no, with the only exception being the existing plain SETTINGS index_granularity = 8192.
  • Attempted the same run on the head after changes; the environment showed /bin/sh: php: not found, no docker binary, and apt installation blocked by permission errors; php remains unavailable and the run would expect contract markers to be yes for several features (shared_order_expr, shared_allow_nullable_key_conditional, low_cardinality_const, low_cardinality_required_nullable_logic, live_sort_key_test, and system_tables_sorting_key_query) once environment constraints are resolved.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (1): Last reviewed commit: "Backport: lead ClickHouse audit sort key..." | Re-trigger Greptile

@lohanidamodar lohanidamodar merged commit 5266d5c into 2.4.x Jun 22, 2026
4 checks passed
@lohanidamodar lohanidamodar deleted the feat/2.4.x-tenant-sort-key branch June 22, 2026 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant